package _6_泛型;


public class _3_编写泛型 {

    //编写泛型类

    /**
     * 1.用String，来编写类
     */
    class Pair{
        private String first;
        private String last;

        public Pair(String first,String last){
            this.first = first;
            this.last = last;
        }

        public String getFirst(){
            return this.first;
        }

        public String getLast(){
            return this.last;
        }

    }

    /**
     *
     * 2.把特定类型String替换为T，并申明<T>
     *
     */
    class Pair1<T>{
        private T first;
        private T last;

        public Pair1(T first,T last){
            this.first = first;
            this.last = last;
        }

        public T getFirst(){
            return this.first;
        }

        public T getLast(){
            return this.last;
        }
    }

    /**
     *
     * 定义多个泛型
     *
     */
    class Pair2<T,K>{
        private T first;
        private K last;

        public Pair2(T first,K last){
            this.first = first;
            this.last = last;
        }

        public T getFirst(){
            return this.first;
        }
        public K getLast(){
            return this.last;
        }

        //使用时，需要指出两种类型
        //Pair<String,Integer> pair = new Pair<>("jby",123);

    }

}
